var BP={};var Sha1={};
Sha1.hash=function(a,c){(typeof c=="undefined"||c)&&(a=Utf8.encode(a));var b=[1518500249,1859775393,2400959708,3395469782];a+=String.fromCharCode(128);for(var d=Math.ceil((a.length/4+2)/16),k=Array(d),j=0;j<d;j++){k[j]=Array(16);for(var l=0;l<16;l++)k[j][l]=a.charCodeAt(j*64+l*4)<<24|a.charCodeAt(j*64+l*4+1)<<16|a.charCodeAt(j*64+l*4+2)<<8|a.charCodeAt(j*64+l*4+3)}k[d-1][14]=(a.length-1)*8/Math.pow(2,32);k[d-1][14]=Math.floor(k[d-1][14]);k[d-1][15]=(a.length-1)*8&4294967295;for(var l=1732584193,i=
4023233417,m=2562383102,p=271733878,q=3285377520,o=Array(80),f,e,h,g,r,j=0;j<d;j++){for(var n=0;n<16;n++)o[n]=k[j][n];for(n=16;n<80;n++)o[n]=Sha1.ROTL(o[n-3]^o[n-8]^o[n-14]^o[n-16],1);f=l;e=i;h=m;g=p;r=q;for(n=0;n<80;n++){var s=Math.floor(n/20),s=Sha1.ROTL(f,5)+Sha1.f(s,e,h,g)+r+b[s]+o[n]&4294967295;r=g;g=h;h=Sha1.ROTL(e,30);e=f;f=s}l=l+f&4294967295;i=i+e&4294967295;m=m+h&4294967295;p=p+g&4294967295;q=q+r&4294967295}return Sha1.toHexStr(l)+Sha1.toHexStr(i)+Sha1.toHexStr(m)+Sha1.toHexStr(p)+Sha1.toHexStr(q)};
Sha1.f=function(a,c,b,d){switch(a){case 0:return c&b^~c&d;case 1:return c^b^d;case 2:return c&b^c&d^b&d;case 3:return c^b^d}};Sha1.ROTL=function(a,c){return a<<c|a>>>32-c};Sha1.toHexStr=function(a){for(var c="",b,d=7;d>=0;d--)b=a>>>d*4&15,c+=b.toString(16);return c};
var Utf8={encode:function(a){a=a.replace(/[\u0080-\u07ff]/g,function(a){a=a.charCodeAt(0);return String.fromCharCode(192|a>>6,128|a&63)});return a=a.replace(/[\u0800-\uffff]/g,function(a){a=a.charCodeAt(0);return String.fromCharCode(224|a>>12,128|a>>6&63,128|a&63)})},decode:function(a){a=a.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g,function(a){a=(a.charCodeAt(0)&15)<<12|(a.charCodeAt(1)&63)<<6|a.charCodeAt(2)&63;return String.fromCharCode(a)});return a=a.replace(/[\u00c0-\u00df][\u0080-\u00bf]/g,
function(a){a=(a.charCodeAt(0)&31)<<6|a.charCodeAt(1)&63;return String.fromCharCode(a)})}},Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(a){for(var c="",b,d,k,j,l,i,m=0,a=Base64._utf8_encode(a);m<a.length;)b=a.charCodeAt(m++),d=a.charCodeAt(m++),k=a.charCodeAt(m++),j=b>>2,b=(b&3)<<4|d>>4,l=(d&15)<<2|k>>6,i=k&63,isNaN(d)?l=i=64:isNaN(k)&&(i=64),c=c+this._keyStr.charAt(j)+this._keyStr.charAt(b)+this._keyStr.charAt(l)+this._keyStr.charAt(i);return c},
decode:function(a){for(var c="",b,d,k,j,l,i=0,a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");i<a.length;)b=this._keyStr.indexOf(a.charAt(i++)),d=this._keyStr.indexOf(a.charAt(i++)),j=this._keyStr.indexOf(a.charAt(i++)),l=this._keyStr.indexOf(a.charAt(i++)),b=b<<2|d>>4,d=(d&15)<<4|j>>2,k=(j&3)<<6|l,c+=String.fromCharCode(b),j!=64&&(c+=String.fromCharCode(d)),l!=64&&(c+=String.fromCharCode(k));return c=Base64._utf8_decode(c)},_utf8_encode:function(a){for(var a=a.replace(/\r\n/g,"\n"),c="",b=0;b<a.length;b++){var d=
a.charCodeAt(b);d<128?c+=String.fromCharCode(d):(d>127&&d<2048?c+=String.fromCharCode(d>>6|192):(c+=String.fromCharCode(d>>12|224),c+=String.fromCharCode(d>>6&63|128)),c+=String.fromCharCode(d&63|128))}return c},_utf8_decode:function(a){for(var c="",b=0,d=c1=c2=0;b<a.length;)d=a.charCodeAt(b),d<128?(c+=String.fromCharCode(d),b++):d>191&&d<224?(c2=a.charCodeAt(b+1),c+=String.fromCharCode((d&31)<<6|c2&63),b+=2):(c2=a.charCodeAt(b+1),c3=a.charCodeAt(b+2),c+=String.fromCharCode((d&15)<<12|(c2&63)<<6|
c3&63),b+=3);return c}},MD5=function(a){function c(a,c){var b,g,d,e,f;d=a&2147483648;e=c&2147483648;b=a&1073741824;g=c&1073741824;f=(a&1073741823)+(c&1073741823);return b&g?f^2147483648^d^e:b|g?f&1073741824?f^3221225472^d^e:f^1073741824^d^e:f^d^e}function b(a,b,g,d,f,e,h){a=c(a,c(c(b&g|~b&d,f),h));return c(a<<e|a>>>32-e,b)}function d(a,b,g,d,e,f,h){a=c(a,c(c(b&d|g&~d,e),h));return c(a<<f|a>>>32-f,b)}function k(a,b,g,d,f,e,h){a=c(a,c(c(b^g^d,f),h));return c(a<<e|a>>>32-e,b)}function j(a,b,g,d,e,f,
h){a=c(a,c(c(g^(b|~d),e),h));return c(a<<f|a>>>32-f,b)}function l(a){var c="",b="",g;for(g=0;g<=3;g++)b=a>>>g*8&255,b="0"+b.toString(16),c+=b.substr(b.length-2,2);return c}var i=[],m,p,q,o,f,e,h,g,a=function(a){for(var a=a.replace(/\r\n/g,"\n"),c="",b=0;b<a.length;b++){var g=a.charCodeAt(b);g<128?c+=String.fromCharCode(g):(g>127&&g<2048?c+=String.fromCharCode(g>>6|192):(c+=String.fromCharCode(g>>12|224),c+=String.fromCharCode(g>>6&63|128)),c+=String.fromCharCode(g&63|128))}return c}(a),i=function(a){var c,
b=a.length;c=b+8;for(var g=((c-c%64)/64+1)*16,d=Array(g-1),f=0,e=0;e<b;)c=(e-e%4)/4,f=e%4*8,d[c]|=a.charCodeAt(e)<<f,e++;d[(e-e%4)/4]|=128<<e%4*8;d[g-2]=b<<3;d[g-1]=b>>>29;return d}(a);f=1732584193;e=4023233417;h=2562383102;g=271733878;for(a=0;a<i.length;a+=16)m=f,p=e,q=h,o=g,f=b(f,e,h,g,i[a+0],7,3614090360),g=b(g,f,e,h,i[a+1],12,3905402710),h=b(h,g,f,e,i[a+2],17,606105819),e=b(e,h,g,f,i[a+3],22,3250441966),f=b(f,e,h,g,i[a+4],7,4118548399),g=b(g,f,e,h,i[a+5],12,1200080426),h=b(h,g,f,e,i[a+6],17,2821735955),
e=b(e,h,g,f,i[a+7],22,4249261313),f=b(f,e,h,g,i[a+8],7,1770035416),g=b(g,f,e,h,i[a+9],12,2336552879),h=b(h,g,f,e,i[a+10],17,4294925233),e=b(e,h,g,f,i[a+11],22,2304563134),f=b(f,e,h,g,i[a+12],7,1804603682),g=b(g,f,e,h,i[a+13],12,4254626195),h=b(h,g,f,e,i[a+14],17,2792965006),e=b(e,h,g,f,i[a+15],22,1236535329),f=d(f,e,h,g,i[a+1],5,4129170786),g=d(g,f,e,h,i[a+6],9,3225465664),h=d(h,g,f,e,i[a+11],14,643717713),e=d(e,h,g,f,i[a+0],20,3921069994),f=d(f,e,h,g,i[a+5],5,3593408605),g=d(g,f,e,h,i[a+10],9,38016083),
h=d(h,g,f,e,i[a+15],14,3634488961),e=d(e,h,g,f,i[a+4],20,3889429448),f=d(f,e,h,g,i[a+9],5,568446438),g=d(g,f,e,h,i[a+14],9,3275163606),h=d(h,g,f,e,i[a+3],14,4107603335),e=d(e,h,g,f,i[a+8],20,1163531501),f=d(f,e,h,g,i[a+13],5,2850285829),g=d(g,f,e,h,i[a+2],9,4243563512),h=d(h,g,f,e,i[a+7],14,1735328473),e=d(e,h,g,f,i[a+12],20,2368359562),f=k(f,e,h,g,i[a+5],4,4294588738),g=k(g,f,e,h,i[a+8],11,2272392833),h=k(h,g,f,e,i[a+11],16,1839030562),e=k(e,h,g,f,i[a+14],23,4259657740),f=k(f,e,h,g,i[a+1],4,2763975236),
g=k(g,f,e,h,i[a+4],11,1272893353),h=k(h,g,f,e,i[a+7],16,4139469664),e=k(e,h,g,f,i[a+10],23,3200236656),f=k(f,e,h,g,i[a+13],4,681279174),g=k(g,f,e,h,i[a+0],11,3936430074),h=k(h,g,f,e,i[a+3],16,3572445317),e=k(e,h,g,f,i[a+6],23,76029189),f=k(f,e,h,g,i[a+9],4,3654602809),g=k(g,f,e,h,i[a+12],11,3873151461),h=k(h,g,f,e,i[a+15],16,530742520),e=k(e,h,g,f,i[a+2],23,3299628645),f=j(f,e,h,g,i[a+0],6,4096336452),g=j(g,f,e,h,i[a+7],10,1126891415),h=j(h,g,f,e,i[a+14],15,2878612391),e=j(e,h,g,f,i[a+5],21,4237533241),
f=j(f,e,h,g,i[a+12],6,1700485571),g=j(g,f,e,h,i[a+3],10,2399980690),h=j(h,g,f,e,i[a+10],15,4293915773),e=j(e,h,g,f,i[a+1],21,2240044497),f=j(f,e,h,g,i[a+8],6,1873313359),g=j(g,f,e,h,i[a+15],10,4264355552),h=j(h,g,f,e,i[a+6],15,2734768916),e=j(e,h,g,f,i[a+13],21,1309151649),f=j(f,e,h,g,i[a+4],6,4149444226),g=j(g,f,e,h,i[a+11],10,3174756917),h=j(h,g,f,e,i[a+2],15,718787259),e=j(e,h,g,f,i[a+9],21,3951481745),f=c(f,m),e=c(e,p),h=c(h,q),g=c(g,o);return(l(f)+l(e)+l(h)+l(g)).toLowerCase()};var Controller=Cairngorm.FrontController.extend({init:function(){this._super();this.addCommand(ViewChangeEvent.VIEW_HOME_MODULE,ViewHomeModuleCommand);this.addCommand(ViewChangeEvent.VIEW_EXERCISE_MODULE,ViewExerciseModuleCommand);this.addCommand(ViewChangeEvent.VIEW_EVALUATION_MODULE,ViewEvaluationModuleCommand);this.addCommand(ViewChangeEvent.VIEW_SUBTITLE_MODULE,ViewSubtitleModuleCommand);this.addCommand(ViewChangeEvent.VIEW_ABOUT_MODULE,ViewAboutModuleCommand);this.addCommand(ViewChangeEvent.VIEW_CONFIG_MODULE,
ViewConfigModuleCommand);this.addCommand(ViewChangeEvent.VIEW_REGISTER_MODULE,ViewRegisterModuleCommand);this.addCommand(ViewChangeEvent.VIEW_LOGIN_POPUP,ToggleLoginPopupCommand);this.addCommand(ViewChangeEvent.RELOAD_STATE,ReloadStateCommand);this.addCommand(LoginEvent.PROCESS_LOGIN,ProcessLoginCommand);this.addCommand(LoginEvent.SIGN_OUT,SignOutCommand);this.addCommand(HomepageEvent.LATEST_USER_UPLOADED_VIDEOS,LatestUploadedVideosCommand);this.addCommand(HomepageEvent.BEST_RATED_VIDEOS_SIGNED_IN,
SignedBestVideosCommand);this.addCommand(HomepageEvent.LATEST_USER_ACTIVITY,LatestUserActivityCommand);this.addCommand(ExerciseEvent.EXERCISE_SELECTED,ExerciseSelectedCommand);this.addCommand(ExerciseEvent.GET_RECORDABLE_EXERCISES,GetRecordableExercisesCommand);this.addCommand(ExerciseEvent.REC_START,StartRecordingCommand);this.addCommand(ExerciseEvent.RECORDING_ABORTED,RecordingAbortedCommand);this.addCommand(ExerciseEvent.SAVE_RESPONSE,SaveResponseCommand);this.addCommand(ExerciseEvent.WATCH_RESPONSE,
WatchResponseCommand);this.addCommand(ExerciseEvent.RECORD_AGAIN,RecordAgainCommand);this.addCommand(ConfigurationEvent.VIEW_MIC_TESTER,ViewMicTesterCommand);this.addCommand(ConfigurationEvent.VIEW_WEBCAM_TESTER,ViewWebcamTesterCommand);this.addCommand(EvaluationEvent.VIEW_PENDING_ASSESMENTS,ViewPendingAssesmentsCommand);this.addCommand(EvaluationEvent.VIEW_CURRENTLY_ASSESSED_TO_USER,ViewCurrentlyAssessedToUserCommand);this.addCommand(EvaluationEvent.VIEW_CURRENTLY_ASSESSED_BY_USER,ViewCurrentlyAssessedByUserCommand);
this.addCommand(EvaluationEvent.VIEW_ASSESSED_ASSESMENT,ViewAssessedAssesmentCommand);this.addCommand(EvaluationEvent.VIEW_REVISION_ASSESMENT,ViewRevisedAssesmentCommand);this.addCommand(EvaluationEvent.VIEW_EVALUATION_ASSESMENT,ViewEvaluationAssesmentCommand);this.addCommand(RegisterEvent.REGISTER_USER,RegisterUserCommand);this.addCommand(RegisterEvent.ACTIVATE_USER,ActivateUserCommand);this.addCommand(LocaleEvent.CHANGE,LocaleChangedCommand)}});function ExerciseManager(){this.bpPlayer=null;this.bpPlayerStates={PLAY_STATE:0,PLAY_BOTH_STATE:1,RECORD_MIC_STATE:2,RECORD_BOTH_STATE:3};this.selectedLocale=this.selectedRole=this.selectedResponse=this.selectedExercise=this.currentResponse=this.currentExercise=this.exerciseId=this.exerciseTitle=this.exerciseName=null;this.exerciseStartedPlaying=false;this.cueManager=null;this.cueManagerReady=false;this.recordedFilename=null;var a=this;this.loadSelectedExercise=function(a){this.bpPlayer=a;this.cueManager=
new cuePointManager;this.setupVideoPlayer();this.onExerciseSelected()};this.loadSelectedResponse=function(a){this.bpPlayer=a;this.cueManager=new cuePointManager;this.setupVideoPlayer();this.onResponseSelected()};this.loadExerciseFromContent=function(a){var b=$("section.exerciseInfo"),d=b.data("id"),b=b.data("name");this.selectedExercise=new ExerciseVO(d,b,null);this.loadSelectedExercise(a)};this.loadResponseFromContent=function(a){var b=$("section.evaluationDetails"),d=b.data("id"),k=b.data("name");
this.selectedExercise=new ExerciseVO(d,k,null);this.selectedResponse={responseName:b.data("responsename"),characterName:b.data("charname"),responseId:b.data("responseid"),subtitleId:b.data("subtitleid")};this.loadSelectedResponse(a)};this.setupVideoPlayer=function(){this.bpPlayer.addEventListener("onRecordingAborted","BP.EM.recordingAbortedListener");this.bpPlayer.addEventListener("onRecordingFinished","BP.EM.recordingFinishedListener")};this.onExerciseSelected=function(a){this.exerciseName=this.selectedExercise.name;
this.exerciseTitle=this.selectedExercise.title;this.exerciseId=this.selectedExercise.id;this.currentResponse=null;this.currentExercise=a;this.cueManagerReady=false;this.prepareExercise();this.resetCueManager();this.prepareCueManager()};this.onResponseSelected=function(){this.exerciseName=this.selectedExercise.name;this.exerciseTitle=this.selectedExercise.title;this.exerciseId=this.selectedExercise.id;this.responseName=this.selectedResponse.responseName;this.currentExercise=this.selectedExercise;this.currentResponse=
this.selectedResponse;this.cueManagerReady=false;this.resetCueManager();this.prepareCueManagerEvaluation()};this.prepareExercise=function(){this.bpPlayer&&(this.bpPlayer.stopVideo(),this.bpPlayer.state(this.bpPlayerStates.PLAY_STATE),this.bpPlayer.videoSource(this.exerciseName))};this.resetComp=function(){this.bpPlayer&&(this.bpPlayer.endVideo(),this.bpPlayer.setSubtitle(""),this.bpPlayer.videoSource(""),this.bpPlayer.state(this.bpPlayerStates.PLAY_STATE))};this.showArrows=function(){this.bpPlayer&&
(this.bpPlayer.arrows(true),this.bpPlayer.setArrows(this.cueManager.cues2rolearray(),this.selectedRole))};this.hideArrows=function(){this.bpPlayer&&(this.bpPlayer.arrows(false),this.bpPlayer.removeArrows())};this.setupRecording=function(){if(this.bpPlayer)this.selectedRole=$("select#recRole > option:selected").val(),this.selectedLocale=$("select#recLocale > option:selected").val(),this.setupRecordingCommands(),$("input[name=recordingMethod]:checked").val()=="micOnly"?this.bpPlayer.state(this.bpPlayerStates.RECORD_MIC_STATE):
this.bpPlayer.state(this.bpPlayerStates.RECORD_BOTH_STATE),this.showArrows(),this.showRecordingOptions()};this.resetCueManager=function(){this.cueManager.reset();this.bpPlayer.removeEventListener("onEnterFrame","BP.EM.enterFrameListener")};this.prepareCueManager=function(){this.cueManager.setVideo(this.exerciseId);this.cueManager.addEventListener("onSubtitlesRetrieved",a.onSubtitlesRetrieved);this.selectedLocale=$("select#recLocale > option:selected").val();this.cueManager.setCuesFromSubtitleUsingLocale(this.selectedLocale);
this.bpPlayer.removeEventListener("onEnterFrame","BP.EM.enterFrameListener");this.bpPlayer.addEventListener("onEnterFrame","BP.EM.enterFrameListener")};this.prepareCueManagerEvaluation=function(){this.cueManager.addEventListener("onSubtitlesRetrieved",a.onSubtitlesRetrieved);this.cueManager.setCuesFromSubtitleUsingId(this.currentResponse.subtitleId);this.bpPlayer.removeEventListener("onEnterFrame","BP.EM.enterFrameListener");this.bpPlayer.addEventListener("onEnterFrame","BP.EM.enterFrameListener")};
this.enterFrameListener=function(a){this.cueManager.monitorCuePoints(a)};this.showRecordingOptions=function(){$("article.exerciseInfo").fadeOut("fast",function(){var a=$("article.recordingEndOptions");a.find("button:lt(3)").attr("disabled","disabled");a.fadeIn()})};this.hideRecordingOptions=function(){$("article.recordingEndOptions").fadeOut("fast",function(){$("article.exerciseInfo").fadeIn()})};this.onSubtitlesRetrieved=function(){a.currentResponse==void 0?a.setupPlayCommands():(a.bpPlayer.state(a.bpPlayerStates.PLAY_BOTH_STATE),
a.bpPlayer.videoSource(a.exerciseName),a.bpPlayer.secondSource(a.responseName),a.selectedRole=a.currentResponse.characterName,a.setupRecordingCommands(),a.bpPlayer.addEventListener("onMetadataRetrieved","BP.EM.onMetadataRetrieved"))};this.setupPlayCommands=function(){var a=this.cueManager.getCuelist();if(!(a.length<=0)){for(var b in a)a[b].setStartCommand(new onPlaybackCuePoint(a[b],this.bpPlayer)),a[b].setEndCommand(new onPlaybackCuePoint(null,this.bpPlayer));this.cueManagerReady=true;this.videoStartedPlayingListener(null)}};
this.setupRecordingCommands=function(){var a=this.cueManager.getCuelist();if(!(a.length<=0)){for(var b in a)a[b].role!=this.selectedRole?(a[b].setStartCommand(new onRecordingOtherRoleCuePoint(a[b],this.bpPlayer)),a[b].setEndCommand(new onPlaybackCuePoint(null,this.bpPlayer))):(a[b].setStartCommand(new onRecordingSelectedRoleStartCuePoint(a[b],this.bpPlayer)),a[b].setEndCommand(new onRecordingSelectedRoleStopCuePoint(this.bpPlayer)));this.bpPlayer.seek(false);this.cueManagerReady=true}};this.watchResponse=
function(){a.showArrows();a.setupRecordingCommands();a.bpPlayer.videoSource(a.exerciseName);a.bpPlayer.state(a.bpPlayerStates.PLAY_BOTH_STATE);a.bpPlayer.secondSource(a.recordedFilename);a.bpPlayer.seek(false)};this.setupReplayCommands=function(){var a=this.cueManager.getCuelist();if(!(a.length<=0)){for(var b in a)a[b].setStartCommand(new onReplayRecordingCuePoint(a[b],this.bpPlayer)),a[b].setEndCommand(new onReplayRecordingCuePoint(null,this.bpPlayer));this.cueManagerReady=true}};this.onMetadataRetrieved=
function(){this.showArrows()};this.videoStartedPlayingListener=function(){};this.recordingAbortedListener=function(){alert("Devices not working");this.recordingError();this.prepareExercise();this.resetCueManager()};this.recordingFinishedListener=function(a){this.recordedFilename=a;this.setupRecordingCommands();this.bpPlayer.videoSource(this.exerciseName);this.bpPlayer.state(this.bpPlayerStates.PLAY_BOTH_STATE);this.bpPlayer.secondSource(this.recordedFilename);this.bpPlayer.seek(false);$("article.recordingEndOptions > button:lt(3)").removeAttr("disabled")};
this.recordingError=function(){this.hideArrows();this.bpPlayer.unattachUserDevices();this.bpPlayer.state(this.bpPlayerStates.PLAY_STATE);this.bpPlayer.removeEventListener("onEnterFrame","bpExercises.onEnterFrameListener");this.hideRecordingOptions()};this.saveResponse=function(){var c=this.cueManager.currentSubtitle(),b=this.bpPlayer.duration();BP.Services.send(false,"saveResponse",{userId:null,exerciseId:a.exerciseId,fileIdentifier:a.recordedFilename,isPrivate:true,thumbnailUri:"nothumb.png",source:"Red5",
duration:b,addingDate:null,ratingAmount:0,characterName:a.selectedRole,transcriptionId:0,subtitleId:c},this.saveResponseCallback)};this.saveResponseCallback=function(a){a==void 0||a.response==void 0?alert("Error while saving the response. Please try again later"):BP.Services.send(false,"makePublic",responseId,this.publishResponseCallback)};this.publishResponseCallback=function(a){a==void 0||a.response==void 0||a.response.creditCount==void 0?alert("Error updating response's status"):(a=a.response,
$("span#creditCount").text(a.creditCount),alert("Your response has been published. Thanks for your collaboration."))}};function ConfigurationManager(){this.bpWebcamTester=this.bpMicTester=null;this.setupComponent=function(a,c){if(c=="mic"&&a!=null)this.bpMicTester=a;if(c=="webcam"&&a!=null)this.bpWebcamTester=a;this.addEventListeners()};this.addEventListeners=function(){this.bpWebcamTester&&(this.bpWebcamTester.addEventListener("onWebcamTestResult","BP.CM.webcamTestResultListener"),this.bpWebcamTester.addEventListener("onDevicesNotAllowed","BP.CM.devicesNotAllowedListener"),this.bpWebcamTester.addEventListener("onFileNotFound",
"BP.CM.fileNotFoundListener"));this.bpMicTester&&(this.bpMicTester.addEventListener("onMicrophoneTestResult","BP.CM.microphoneTestResultListener"),this.bpMicTester.addEventListener("onDevicesNotAllowed","BP.CM.devicesNotAllowedListener"),this.bpMicTester.addEventListener("onFileNotFound","BP.CM.fileNotFoundListener"))};this.webcamTestResultListener=function(a){a?alert("Webcam test passed"):alert("Webcam test failed")};this.microphoneTestResultListener=function(a){a?alert("Microphone test passed"):
alert("Microphone test failed")};this.devicesNotAllowedListener=function(){alert("You must give permission to access your devices in order to pass this test")};this.fileNotFoundListener=function(){alert("Can't find the test file you've just recorded")}};BP.CMS=function(){function a(){q.find("ul > li > a").not(":last").hover(function(){$(this).parent().css("background","url(themes/babelium/images/separator.png) no-repeat center right, url(themes/babelium/images/button_nav_highlight_"+$(this).attr("class")+".png) no-repeat 50% 58%")},function(){$(this).parent().css("background","url(themes/babelium/images/separator.png) no-repeat center right")});q.find("ul > li > a:last").hover(function(){$(this).parent().css("background"," url(themes/babelium/images/button_nav_highlight_"+
$(this).attr("class")+".png) no-repeat 50% 58%")},function(){$(this).parent().css("background","none")})}function c(){var a=$("select#localebox").css("display","none");a.parent().append("<div class='localebox'></div>");var c=$(".localebox");c.append("<div class='selectBox'></div>");c.append("<ul class='dropDown'></ul>");var b=$(".selectBox"),d=$(".dropDown").hide();a.find("option").each(function(){var c=$(this),e=$(this).text(),e="<img src='"+$(this).data("icon")+"' width='16' height='16' align='left' hspace='3' vspace='3' alt='"+
e+"' />"+e;$(this).is(":selected")&&b.html(e+"<img src='themes/babelium/images/arrow-down.png'alignt='left' style='float:right; margin-right: 3px;' />");e=$("<li>",{html:e});d.append(e);e.click(function(){b.html($(this).html()+"<img src='themes/babelium/images/arrow-down.png'alignt='left' style='float:right; margin-right: 3px;' />");d.slideUp();a.val(c.val());a.change()})});b.click(function(){d.slideToggle()});$(document).click(function(){if(d.is(":animated"))return false;d.slideUp()})}function b(){BP.SM.at("home")&&
!BP.SM.action()?p("#motdmessageshelper","#motdmessages"):BP.SM.at("evaluate")&&BP.SM.action("touser")&&BP.SM.params()!=null&&p("#evaluationUserNames","#userEvaluationsContainer")}function d(){BP.SM.at("home")&&BP.SM.action("activity")&&(l("#assesmentsReceived"),l("#assesmentsGiven"))}function k(){BP.SM.at("practice")?i("section.exerciseList",".exerciseContainer",".exercise",{title:".exerciseTitle",description:"p.exerciseDescription"}):BP.SM.at("evaluate")&&i("section.evaluationItemList",".assesmentsContainer",
".evaluationItem",{title:".evaluationTitle",description:".evaluationTitle"})}function j(a,c){c==true?$(a).each(function(){$(this).raty({path:"themes/babelium/images/raty",readOnly:$(this).data("readonly"),half:true,start:$(this).data("rating")/2,size:24,starHalf:"star-half-big.png",starOff:"star-off-big.png",starOn:"star-on-big.png"})}):$(a).each(function(){$(this).raty({path:"themes/babelium/images/raty",readOnly:$(this).data("readonly"),half:true,start:$(this).data("rating")/2})})}function l(a){a=
$(a).dataTable({bJQueryUI:true,sPaginationType:"full_numbers"});j($(a.fnGetNodes()).find(".raty"))}function i(a,c,b,d,e){typeof e=="undefined"&&(e=10);$(a).jplist({filter:d,filter_path:".paginationFilter",pagingbox:".paginationButtons",pageinfo:".paginationInfo",paging_dd_path:".paginationPage-by",items_box:c,item_path:b,items_on_page:e,redraw_callback:m})}function m(){j(".raty");var a=$("#exerciseVideoContainer");a.length!=0&&a.find("article").each(function(){var a=$(this);a.click(function(){(new ExerciseEvent(ExerciseEvent.EXERCISE_SELECTED,
new ExerciseVO(a.data("id"),a.data("name"),a.data("title")))).dispatch()})})}function p(a,c){if(!($(a).length==0||$(c).length==0))return function(){function b(a){a<1||a>f||($(c+" > *:nth-child("+e+")").fadeOut(500,function(){$(c+" > *:nth-child("+a+")").fadeIn(500)}),e=a)}var e=1,d=c,f=$(a+" > *").length;$(d+" > *").css("display","none");$(d+" > *:first-child").css("display","block");$(a+" > *").each(function(a){$(this).click(function(){b(a+1)})});return{next:function(){var a=e+1;a>f?b(1):b(a)},prev:function(){var a=
e-1;a>1?b(f):b(a)},show:function(a){b(a)}}}()}var q,o,f,e=false,h=false;return{init:function(){e||($("#usernav"),q=$("#mainnav"),$("#searchnav"),o=$("section#maincontent"),f=$("aside#loader > div"),a(),c(),b(),d(),k(),BP.SM.at("home")&&!BP.SM.action("activity")&&j(".raty"),(BP.SM.at("practice")&&BP.SM.action("view")||BP.SM.at("evaluate")&&BP.SM.params()!=null)&&j(".ratyPreview",true),e=true)},prepareMainContent:function(a,c,b){if(!h&&e){h=true;var d=$("aside#motd"),i=o.find("header"),j=o.offset().top;
f.css("top",j);f.find("p").html("Loading <strong>"+a+"</strong>");f.slideDown();$("html, body").scrollTop()>j&&$("html, body").animate({scrollTop:j},"slow");$("#maincontent > section").length>0?(d.length>0&&!b&&(d.fadeOut("fast",function(){d.remove()}),i.slideDown()),b&&i.slideUp(),$.when($("#maincontent > section").fadeOut()).done(function(){$("#maincontent > section").remove();$("aside#tabBarContainer").length>0&&$("aside#tabBarContainer").remove();c()})):($("aside#tabBarContainer").length>0&&$("aside#tabBarContainer").remove(),
c())}},prepareExerciseView:function(a,c){if(!h&&e){h=true;typeof c=="undefined"&&(c="exercise");var b=o.offset().top;f.css("top",b+o.find("header").outerHeight());f.find("p").text("Retrieving "+c+" information");f.slideDown();$("html, body").animate({scrollTop:b},"slow",function(){a()})}},viewStack:function(a,c){return!e?void 0:p(a,c)},reloadViewStacks:function(){e&&b()},reloadDataTables:function(){e&&d()},reloadPaginations:function(){e&&k()},reloadRatings:function(){e&&(BP.SM.at("home")&&!BP.SM.action("activity")&&
j(".raty"),(BP.SM.at("practice")&&BP.SM.action("view")||BP.SM.at("evaluate"))&&j(".ratyPreview",true))},innerMainContent:function(a){h&&(a=$.parseJSON(a),$("#maincontent > header > h1").text(a.title),$(a.content).hide().appendTo("#maincontent").fadeIn(),f.slideUp(),this.reloadViewStacks(),this.reloadDataTables(),this.reloadPaginations(),this.reloadRatings(),h=false)},innerExerciseView:function(a,c){if(h){var b="",d="";typeof c=="undefined"?(d="section.exerciseInfo",b="aside#loader"):(d="section.evaluationDetails",
b="aside#tabBarContainer");var e=this,a=$.parseJSON(a),i=$(a.content).hide();$(d).length>0?$(d).fadeOut("fast",function(){$(d).remove();i.insertAfter(b).fadeIn();e.reloadRatings();e.reloadViewStacks();f.slideUp()}):(i.insertAfter(b).fadeIn(),e.reloadRatings(),e.reloadViewStacks(),f.slideUp());h=false}},toggleLoginPopup:function(){e&&($("aside#popup").is(":visible")?this.hideLoginPopup():this.showLoginPopup())},hideLoginPopup:function(){e&&$("aside#popup").fadeOut("fast",function(){document.getElementById("loginForm").reset()})},
showLoginPopup:function(){e&&$("aside#popup").fadeIn()},abortLoading:function(){h&&(f.slideUp(),h=false)}}}();BP.SM=function(){var a={},c=true;return{init:function(){if(typeof window.history=="undefined"||typeof window.history.pushState!="function")console.warn("Disabling state handle"),c=false;var a=(/module=(.+?)(&|$)/.exec(location.search)||[,"home"])[1],d=(/action=(.+?)(&|$)/.exec(location.search)||[,void 0])[1],k=(/params=(.+?)(&|$)/.exec(location.search)||[,void 0])[1];this.pushState(null,{module:a,action:d,params:k})},pushState:function(b,d){var k="?",j;for(j in d)d[j]!=void 0&&(k+=k.length==1?j+"="+
d[j]:"&"+j+"="+d[j]);c&&window.history.pushState(d,b,k);a=d},currentState:function(){return a},onPopState:function(a){if(!(typeof a.state=="undefined"||a.state==null)){a=a.state;if(a.module=="home")a.state="min";(new ViewChangeEvent(ViewChangeEvent.RELOAD_STATE,a)).dispatch()}},at:function(c){return typeof c=="undefined"?typeof a.module=="undefined"?null:a.module:typeof a.module=="undefined"?false:a.module==c},action:function(c){return typeof c=="undefined"?typeof a.action=="undefined"?null:a.action:
typeof a.action=="undefined"?false:a.action==c},params:function(c){return typeof actionName=="undefined"?typeof a.params=="undefined"?null:a.params:typeof a.params=="undefined"?false:a.params==c}}}();function ApiGateway(){this.protocol="http://";this.host="babelium/html5/api/";this.endpoint="rest.php";this.lastRandomizer="";this.statToken="myMusicFightsAgainstTheSystemThatTeachesToLiveAndDie";this.token=this.authToken=this.commToken="";var a=this;this.send=function(c,b,d,k){var c=(c?"https://":"http://")+this.host+this.endpoint+"?"+b,j={};j.method=b;if(d!=null)j.parameters=d;if(k==null)k=a.onServiceSuccess;this.token=this.generateToken(b);j.header={token:this.token,session:this.getSessionID,uuid:this.getUUID};
$.support.cors=true;$.ajax({type:"POST",url:c,data:j,success:k,error:function(c,b,d){a.onServiceError(c,b,d)},xhrFields:{withCredentials:true},crossDomain:true})};this.getCommunicationToken=function(){var c=this.protocol+this.host+this.endpoint+"?getCommunicationToken",b={method:"getCommunicationToken"};b.parameters={secretKey:MD5(this.getSessionID)};b.header={session:this.getSessionID,uuid:this.getUUID};$.post(c,b,BP.Services.onCommunicationTokenSuccess,"json").error(function(c){a.onServiceError(c)})};
this.onCommunicationTokenSuccess=function(c){a.commToken=c.response;BP.onCommunicationReady()};this.onServiceSuccess=function(){};this.onServiceError=function(a){a=jQuery.parseJSON(a.responseText);console.log(a)};this.createRandomSalt=function(){for(var a="",b=0;b<6;)a+=Math.floor(Math.random()*16).toString(16),b++;return a!==this.lastRandomizer?a:createRandomSalt()};this.generateToken=function(a){var b=this.createRandomSalt(),a=Sha1.hash(a+":"+this.commToken+":"+this.statToken+":"+b);return b+a};
this.getUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0;return(a=="x"?b:b&3|8).toString(16)}).toUpperCase()}();this.getSessionID=function(){var a=document.cookie.match("(^|;) ?PHPSESSID=([^;]*)(;|$)");return a?unescape(a[2]):null}()};var ConfigurationEvent=Cairngorm.Event.extend({init:function(a){this._super(a)}});ConfigurationEvent.VIEW_MIC_TESTER="viewMicTester";ConfigurationEvent.VIEW_WEBCAM_TESTER="viewWebcamTester";var EvaluationEvent=Cairngorm.Event.extend({init:function(a,c,b,d,k){this._super(a,{evaluation:c,responseId:b,sortField:d,pageNumber:k})}});EvaluationEvent.VIEW_PENDING_ASSESMENTS="viewPendingAssesments";EvaluationEvent.VIEW_CURRENTLY_ASSESSED_TO_USER="viewAssessedToUser";EvaluationEvent.VIEW_CURRENTLY_ASSESSED_BY_USER="viewAssessedByUser";EvaluationEvent.VIEW_EVALUATION_ASSESMENT="viewEvaluationAsesment";EvaluationEvent.VIEW_REVISION_ASSESMENT="viewRevisionAssesment";
EvaluationEvent.VIEW_ASSESSED_ASSESMENT="viewAssessedAssesment";var ExerciseEvent=Cairngorm.Event.extend({init:function(a,c,b,d){this._super(a,{exercise:c,report:b,score:d})}});ExerciseEvent.EXERCISE_SELECTED="exerciseSelected";ExerciseEvent.GET_RECORDABLE_EXERCISES="getRecordableExercises";ExerciseEvent.REC_START="exerciseRecStart";ExerciseEvent.RECORDING_ABORTED="exerciseRecAborted";ExerciseEvent.SAVE_RESPONSE="exerciseSaveResponse";ExerciseEvent.WATCH_RESPONSE="exerciseWatchResponse";ExerciseEvent.RECORD_AGAIN="exerciseRecordAgain";var HomepageEvent=Cairngorm.Event.extend({init:function(a){this._super(a)}});HomepageEvent.BEST_RATED_VIDEOS_SIGNED_IN="bestRatedVideosSignedIn";HomepageEvent.LATEST_USER_UPLOADED_VIDEOS="latestUserUploadedVideos";HomepageEvent.LATEST_USER_ACTIVITY="latestUserActivity";var LocaleEvent=Cairngorm.Event.extend({init:function(a,c){this._super(a,c)}});LocaleEvent.CHANGE="localeChanged";var LoginEvent=Cairngorm.Event.extend({init:function(a,c){this._super(a,c)}});LoginEvent.PROCESS_LOGIN="processLogin";LoginEvent.SIGN_OUT="signOut";var RegisterEvent=Cairngorm.Event.extend({init:function(a,c){this._super(a,c)}});RegisterEvent.REGISTER_USER="registerUser";RegisterEvent.ACTIVATE_USER="activateUser";var ViewChangeEvent=Cairngorm.Event.extend({init:function(a,c){this._super(a,c)}});ViewChangeEvent.VIEW_HOME_MODULE="viewHomeModule";ViewChangeEvent.VIEW_EXERCISE_MODULE="viewExerciseModule";ViewChangeEvent.VIEW_EVALUATION_MODULE="viewEvaluationModule";ViewChangeEvent.VIEW_SUBTITLE_MODULE="viewSubtitleModule";ViewChangeEvent.VIEW_ABOUT_MODULE="viewAboutModule";ViewChangeEvent.VIEW_CONFIG_MODULE="viewConfigModule";ViewChangeEvent.VIEW_REGISTER_MODULE="viewRegisterModule";
ViewChangeEvent.VIEW_LOGIN_POPUP="viewLoginPopup";ViewChangeEvent.RELOAD_STATE="reloadState";var ReloadStateCommand=Cairngorm.Command.extend({execute:function(){var a=this,c=this.data.module;if(!(c==null||c==void 0)){var b="action="+(typeof this.data.action=="undefined"?"":this.data.action)+"&params="+(typeof this.data.params=="undefined"?"":this.data.params)+"&state="+(typeof this.data.state=="undefined"?"":this.data.state),d=Cairngorm.ServiceLocator.getHttpService(c);BP.CMS.prepareMainContent(c,function(){d.call(b,a)},c=="home")}},onResult:function(a){BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();
alert("{{$ERROR_LOADING_LAST_MODULE}}")}});var ToggleLoginPopupCommand=Cairngorm.Command.extend({execute:function(){BP.CMS.toggleLoginPopup()}});var ViewHomeModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_HOME_MODULE}}",function(){BP.HomeDelegate.viewHomeModule(a,a.data===true)},true)},onResult:function(a){BP.SM.pushState("{{$TITLE_HOME_MODULE}}",{module:"home"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_HOME_MODULE}}")}});var LatestUploadedVideosCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_LATEST_UPLOADED_VIDEOS}}",function(){BP.HomeDelegate.latestAvailableVideos(a)},true)},onResult:function(a){BP.SM.pushState("{{$TITLE_LATEST_UPLOADED_VIDEOS}}",{module:"home",action:"uploaded"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_LATEST_UPLOADED_VIDEOS}}")}});var SignedBestVideosCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_BEST_VIDEOS}}",function(){BP.HomeDelegate.topScoreMostViewedVideos(a)},true)},onResult:function(a){BP.SM.pushState("{{$TITLE_BEST_VIDEOS}}",{module:"home",action:"rated"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_BEST_VIDEOS}}")}});var LatestUserActivityCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_USER_ACTIVITY}}",function(){BP.HomeDelegate.latestUserActivity(a)},true)},onResult:function(a){BP.SM.pushState("{{$TITLE_USER_ACTIVITY}}",{module:"home",action:"activity"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_USER_ACTIVITY}}")}});var ExerciseSelectedCommand=Cairngorm.Command.extend({execute:function(){var a=this;if(this.data!=null)BP.EM.selectedExercise=this.data.exercise,BP.CMS.prepareExerciseView(function(){BP.PracticeDelegate.viewExerciseByName(a,BP.EM.selectedExercise.name)})},onResult:function(a){BP.SM.pushState(BP.EM.selectedExercise.title+"{{$TITLE_SELECTED_EXERCISE}}",{module:"practice",action:"view",params:BP.EM.selectedExercise.name});BP.CMS.innerExerciseView(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_SELECTED_EXERCISE}}")}});var GetRecordableExercisesCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_EXERCISE_MODULE}}",function(){BP.PracticeDelegate.getRecordableExercises(a)})},onResult:function(a){BP.pushState("{{$TITLE_EXERCISE_MODULE}}","?module=practice",{module:"practice"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_EXERCISE_MODULE}}")}});var RecordAgainCommand=Cairngorm.Command.extend({execute:function(){BP.EM.selectedExercise!=null&&(BP.EM.bpPlayer.videoSource(BP.EM.exerciseName),BP.EM.setupRecording())}});var RecordingAbortedCommand=Cairngorm.Command.extend({execute:function(){BP.EM.selectedExercise!=null&&(BP.EM.recordingError(),BP.EM.prepareExercise(),BP.EM.resetCueManager(),BP.EM.prepareCueManager())}});var SaveResponseCommand=Cairngorm.Command.extend({execute:function(){BP.EM.selectedExercise!=null&&BP.EM.saveResponse()}});var StartRecordingCommand=Cairngorm.Command.extend({execute:function(){BP.EM.selectedExercise!=null&&BP.EM.setupRecording()}});var ViewExerciseModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.EM.selectedExercise=null;BP.CMS.prepareMainContent("{{$LOADING_EXERCISE_MODULE}}",function(){BP.PracticeDelegate.viewPracticeModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_EXERCISE_MODULE}}",{module:"practice"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_EXERCISE_MODULE}}")}});var WatchResponseCommand=Cairngorm.Command.extend({execute:function(){BP.EM.selectedExercise!=null&&BP.EM.watchResponse()}});var ViewEvaluationModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_EVALUATION_MODULE}}",function(){BP.EvaluationDelegate.viewEvaluationModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_EVALUATION_MODULE}}",{module:"evaluate"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_EVALUATION_MODULE}}")}});var ViewPendingAssesmentsCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_ASSESMENTS_PENDING}}",function(){BP.EvaluationDelegate.viewPendingAssesments(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_ASSESMENTS_PENDING}}",{module:"evaluate",action:"pending"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_ASSESMETS_PENDING}}")}});var ViewCurrentlyAssessedToUserCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_ASSESMENTS_TOUSER}}",function(){BP.EvaluationDelegate.viewAssessedToUser(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_ASSESMENTS_TOUSER}}",{module:"evaluate",action:"touser"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_ASSESMETS_TOUSER}}")}});var ViewCurrentlyAssessedByUserCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_ASSESMENTS_BYUSER}}",function(){BP.EvaluationDelegate.viewAssessedByUser(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_ASSESMENTS_BYUSER}}",{module:"evaluate",action:"byuser"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_ASSESMETS_BYUSER}}")}});var ViewAssessedAssesmentCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.EM.selectedExercise=this.data.evaluation;BP.EM.selectedResponse=this.data.responseId;BP.SM.pushState("{{$TITLE_ASSESMENTS_BYUSER}}",{module:"evaluate",action:"byuser",params:this.data.responseId});BP.CMS.prepareExerciseView(function(){BP.EvaluationDelegate.viewAssessedAssesment(a,a.data.responseId)},"evaluation")},onResult:function(a){BP.CMS.innerExerciseView(a,true)},onFault:function(){BP.CMS.abortLoading();
alert("{{$ERROR_LOADING_ASSESMETS_BYUSER}}")}});var ViewRevisedAssesmentCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.EM.selectedExercise=this.data.evaluation;BP.EM.selectedResponse=this.data.responseId;BP.SM.pushState("{{$TITLE_ASSESMENTS_TOUSER}}",{module:"evaluate",action:"touser",params:this.data.responseId});BP.CMS.prepareExerciseView(function(){BP.EvaluationDelegate.viewRevisedAssesment(a,a.data.responseId)},"evaluation")},onResult:function(a){BP.CMS.innerExerciseView(a,true)},onFault:function(){BP.CMS.abortLoading();
alert("{{$ERROR_LOADING_ASSESMETS_TOUSER}}")}});var ViewEvaluationAssesmentCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.EM.selectedExercise=this.data.evaluation;BP.EM.selectedResponse=this.data.responseId;BP.SM.pushState("{{$TITLE_ASSESMENTS_PENDING}}",{module:"evaluate",action:"pending",params:this.data.responseId});BP.CMS.prepareExerciseView(function(){BP.EvaluationDelegate.viewEvaluationAssesment(a,a.data.responseId)},"evaluation")},onResult:function(a){BP.CMS.innerExerciseView(a,true)},onFault:function(){BP.CMS.abortLoading();
alert("{{$ERROR_LOADING_ASSESMETS_PENDING}}")}});var ViewSubtitleModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_SUBTITLE_MODULE}}",function(){BP.SubtitleDelegate.viewSubtitleModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_SUBTITLE_MODULE}}",{module:"subtitle"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_SUBTITLE_MODULE}}")}});var ViewConfigModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_CONFIG_MODULE}}",function(){BP.ConfigurationDelegate.viewConfigModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_CONFIG_MODULE}}",{module:"config"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_CONFIG_MODULE}}")}});var ViewMicTesterCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_MIC_TEST}}",function(){BP.ConfigurationDelegate.viewMicTester(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_MIC_TEST}}",{module:"config",action:"mic"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_MIC_TEST}}")}});var ViewWebcamTesterCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_WEBCAM_TEST}}",function(){BP.ConfigurationDelegate.viewWebcamTester(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_WEBCAM_TEST}}",{module:"config",action:"webcam"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_WEBCAM_TEST}}")}});var LocaleChangedCommand=Cairngorm.Command.extend({execute:function(){var a=this.data;a!=null&&(window.location.href+=window.location.href.indexOf("?")!=-1?"&locale="+a:"?locale="+a)}});var ViewAboutModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_ABOUT_MODULE}}",function(){BP.AboutDelegate.viewAboutModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_ABOUT_MODULE}}",{module:"about"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_ABOUT_MODULE}}")}});var ProcessLoginCommand=Cairngorm.Command.extend({execute:function(){this.data!=null&&($("li#loginhelper").html("<img src='themes/babelium/images/loading.gif' alt='Loading..' width='16' height='16' />"),BP.AuthDelegate.processLogin(this,this.data))},onResult:function(a){a=$.parseJSON(a);a.content.indexOf("<li>")!=-1?($("li#loginhelper").html(""),$("ul#usernav").html(a.content),BP.CMS.hideLoginPopup(),BP.SM.at("home")?($("aside#motd").fadeOut(500,function(){$(this).remove()}),(new ViewChangeEvent(ViewChangeEvent.VIEW_HOME_MODULE,
true)).dispatch()):(new ViewChangeEvent(ViewChangeEvent.RELOAD_STATE,BP.SM.currentState())).dispatch()):$("li#loginhelper").html(a.content)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOGIN}}")}});var SignOutCommand=Cairngorm.Command.extend({execute:function(){BP.AuthDelegate.signOut(this)},onResult:function(a){a=$.parseJSON(a);a.content.indexOf("<li>")!=-1&&($("li#loginhelper").html(""),$("ul#usernav").html(a.content),BP.SM.at("home")?($("aside#motd").fadeOut(500,function(){$(this).remove()}),(new ViewChangeEvent(ViewChangeEvent.VIEW_HOME_MODULE,true)).dispatch()):(new ViewChangeEvent(ViewChangeEvent.RELOAD_STATE,BP.SM.currentState())).dispatch())},onFault:function(){BP.CMS.abortLoading();
alert("{{$ERROR_LOGIN}}")}});var ViewRegisterModuleCommand=Cairngorm.Command.extend({execute:function(){var a=this;BP.CMS.prepareMainContent("{{$LOADING_REGISTER_FORM}}",function(){BP.RegisterDelegate.viewRegisterModule(a)})},onResult:function(a){BP.SM.pushState("{{$TITLE_REGISTER_FORM}}",{module:"register"});BP.CMS.innerMainContent(a)},onFault:function(){BP.CMS.abortLoading();alert("{{$ERROR_LOADING_REGISTER_FORM}}")}});var RegisterUserCommand=Cairngorm.Command.extend({execute:function(){if(this.data!=null){var a=this;BP.CMS.prepareMainContent("{{$LOADING_REGISTER_FORM}}",function(){BP.RegisterDelegate.processRegister(a,a.data)})}},onResult:function(a){BP.SM.pushState("{{$TITLE_REGISTER_FORM}}",{module:"register"});BP.CMS.innerMainContent(a)},onFault:function(){alert("{{$ERROR_REGISTERING_USER}}")}});var ActivateUserCommand=Cairngorm.Command.extend({execute:function(){this.data!=null&&BP.RegisterDelegate.activateUser(this,this.data)},onResult:function(a){$.parseJSON(a);(new ViewChangeEvent(ViewChangeEvent.VIEW_HOME_MODULE,true)).dispatch()},onFault:function(){alert("{{$ERROR_ACTIVATING_ACCOUNT}}")}});function onPlaybackCuePoint(a,c){this.VP=c;this.cue=a;this.execute=function(){this.cue?this.VP.setSubtitle(this.cue.text,this.cue.textColor):this.VP.setSubtitle("",0)}};function onRecordingOtherRoleCuePoint(a,c){this.VP=c;this.cue=a;this.execute=function(){var a=this.cue.endTime-this.cue.startTime;this.VP.setSubtitle(this.cue.text,this.cue.textColor);this.VP.startTalking(this.cue.role,a);this.VP.highlight(false)}};function onRecordingSelectedRoleStartCuePoint(a,c){this.VP=c;this.cue=a;this.execute=function(){var a=this.cue.endTime-this.cue.startTime;this.VP.muteVideo(true);this.VP.muteRecording(false);this.VP.setSubtitle(this.cue.text,this.cue.textColor);this.VP.startTalking(this.cue.role,a);this.VP.highlight(true)}};function onRecordingSelectedRoleStopCuePoint(a){this.VP=a;this.execute=function(){this.VP.muteRecording(true);this.VP.muteVideo(false);this.VP.setSubtitle("",0);this.VP.highlight(false)}};function onReplayRecordingCuePoint(a,c){this.VP=c;this.cue=a;this.execute=function(){this.cue?(this.VP.setSubtitle(this.cue.text,this.cue.textColor),this.VP.startTalking(this.cue.role,this.cue.endTime-this.cue.startTime)):this.VP.setSubtitle("",0)}};function cueObject(a,c,b,d,k,j,l,i,m){this.defaultParamValues=[0,-1,-1,null,0,null,null,null,16777215];this.subtitleId=a;this.startTime=c;this.endTime=b;this.text=d;this.roleId=k;this.role=j;this.startCommand=l;this.endCommand=i;this.textColor=m==null?defaultParamValues[9]:m;this.executeStartCommand=function(){this.startCommand.execute()};this.executeEndCommand=function(){this.endCommand.execute()};this.setStartCommand=function(a){this.startCommand=a};this.setEndCommand=function(a){this.endCommand=
a}};function cuePointManager(){this.cpm_cuelist=[];this.cpm_subtitleId=this.cpm_exerciseId=-1;this.roleColors=[16777215,16776482,6945792,16609792,355577,16715531,12784841,16739301];this.colorDictionary=[];var a=this;this.reset=function(){cpm_subtitleId=cpm_exerciseId=-1;cpm_cuelist=[]};this.setVideo=function(a){this.cpm_exerciseId=a};this.currentSubtitle=function(){return this.cpm_subtitleId};this.addCue=function(a){this.cpm_cuelist.push(a);this.cpm_cuelist.sort(this.sortByStartTime)};this.setCueAt=function(a,
b){this.cpm_cuelist.setItemAt(a,b)};this.getCueAt=function(a){return this.cpm_cuelist[a]};this.removeCueAt=function(a){return this.cpm_cuelist.removeItemAt(a)};this.getCueIndex=function(a){return this.cpm_cuelist.getItemIndex(a)};this.removeAllCue=function(){this.cpm_cuelist=[]};this.setCueList=function(a){this.cpm_cuelist=a};this.getCuelist=function(){return this.cpm_cuelist};this.sortByStartTime=function(a,b){return a.startTime>b.startTime?1:a.startTime<b.startTime?-1:0};this.sortByEndTime=function(a,
b){return a.endTime>b.endTime?1:a.endTime<b.endTime?-1:0};this.setCueListStartCommand=function(a){for(var b in this.cpm_cuelist)this.cpm_cuelist[b].setStartCommand(a)};this.setCueListEndCommand=function(a){for(var b in this.cpm_cuelist)this.cpm_cuelist[b].setEndCommand(a)};this.monitorCuePoints=function(a){for(var b in this.cpm_cuelist){if(a-0.08<this.cpm_cuelist[b].startTime&&this.cpm_cuelist[b].startTime<a+0.08){this.cpm_cuelist[b].executeStartCommand();break}if(a-0.08<this.cpm_cuelist[b].endTime&&
this.cpm_cuelist[b].endTime<a+0.08){this.cpm_cuelist[b].executeEndCommand();break}}};this.setCuesFromSubtitleUsingLocale=function(c){BP.Services.send(false,"getSubtitleLines",{id:0,exerciseId:this.cpm_exerciseId,language:c},a.subtitlesRetrievedCallback)};this.setCuesFromSubtitleUsingId=function(c){BP.Services.send(false,"getSubtitleLinesUsingId",{subtitleId:c},a.subtitlesRetrievedCallback)};this.subtitlesRetrievedCallback=function(c){c=c.response;a.colorDictionary=[];for(var b in c)typeof c[b]=="object"&&
a.addCueFromSubtitleLine(c[b]);for(b in c){a.cpm_subtitleId=c[b].subtitleId;break}a.subtitlesRetrievedListener()};this.addCueFromSubtitleLine=function(a){for(var b=false,d=this.roleColors[0],k=0;k<this.colorDictionary.length;k++)if(this.colorDictionary[k]==a.exerciseRoleId){b=true;d=this.roleColors[k];break}b||(this.colorDictionary.push(a.exerciseRoleId),d=this.roleColors[this.colorDictionary.length-1]);this.addCue(new cueObject(a.subtitleId,a.showTime,a.hideTime,a.text,a.exerciseRoleId,a.exerciseRoleName,
null,null,d))};this.cues2rolearray=function(){var a=[],b=this.getCuelist(),d;for(d in b)a.push({startTime:b[d].startTime,endTime:b[d].endTime,role:b[d].role});return a};this.addEventListener=function(a,b){switch(a){case "onSubtitlesRetrieved":if(typeof b=="function")this.subtitlesRetrievedListener=b}}};BP.HomeDelegate=function(){return{viewHomeModule:function(a,c){var b=Cairngorm.ServiceLocator.getHttpService("home"),d=!c&&BP.SM.at("home")?{state:"min"}:null;b.call(d,a)},latestAvailableVideos:function(a){Cairngorm.ServiceLocator.getHttpService("home").call({action:"latest",state:"min"},a)},topScoreMostViewedVideos:function(a){Cairngorm.ServiceLocator.getHttpService("home").call({action:"rated",state:"min"},a)},latestUserActivity:function(a){Cairngorm.ServiceLocator.getHttpService("home").call({action:"activity",
state:"min"},a)}}}();BP.PracticeDelegate=function(){return{viewPracticeModule:function(a){Cairngorm.ServiceLocator.getHttpService("practice").call(null,a)},getRecordableExercises:function(a){Cairngorm.ServiceLocator.getHttpService("practice").call(null,a)},viewExerciseByName:function(a,c){c&&Cairngorm.ServiceLocator.getHttpService("practice").call({action:"view",state:"min",params:c},a)}}}();BP.EvaluationDelegate=function(){return{viewEvaluationModule:function(a){Cairngorm.ServiceLocator.getHttpService("evaluate").call(null,a)},viewPendingAssesments:function(a){Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"pending"},a)},viewAssessedToUser:function(a){Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"touser"},a)},viewAssessedByUser:function(a){Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"byuser"},a)},viewAssessedAssesment:function(a,
c){typeof c!="undefined"&&Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"byuser",params:c,state:"min"},a)},viewRevisedAssesment:function(a,c){typeof c!="undefined"&&Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"touser",params:c,state:"min"},a)},viewEvaluationAssesment:function(a,c){typeof c!="undefined"&&Cairngorm.ServiceLocator.getHttpService("evaluate").call({action:"pending",params:c,state:"min"},a)}}}();BP.SubtitleDelegate=function(){return{viewSubtitleModule:function(a){Cairngorm.ServiceLocator.getHttpService("subtitle").call(null,a)}}}();BP.ConfigurationDelegate=function(){return{viewConfigModule:function(a){Cairngorm.ServiceLocator.getHttpService("config").call(null,a)},viewMicTester:function(a){Cairngorm.ServiceLocator.getHttpService("config").call({action:"mic"},a)},viewWebcamTester:function(a){Cairngorm.ServiceLocator.getHttpService("config").call({action:"webcam"},a)}}}();BP.AboutDelegate=function(){return{viewAboutModule:function(a){Cairngorm.ServiceLocator.getHttpService("about").call(null,a)}}}();BP.UserDelegate=function(){return{viewUserModule:function(){}}}();BP.AuthDelegate=function(){return{processLogin:function(a,c){if(c&&typeof c.toBase64=="function"){var b=Cairngorm.ServiceLocator.getHttpService("auth"),d={action:"login",params:c.toBase64()};b.call(d,a)}},signOut:function(a){Cairngorm.ServiceLocator.getHttpService("auth").call({action:"logout"},a)}}}();BP.RegisterDelegate=function(){return{viewRegisterModule:function(a){Cairngorm.ServiceLocator.getHttpService("register").call(null,a)},processRegister:function(a,c){if(c&&typeof c.toBase64=="function"){var b=Cairngorm.ServiceLocator.getHttpService("register"),d={action:"register",params:c.toBase64()};b.call(d,a)}}}}();var LoginVO=Cairngorm.VO.extend({init:function(a,c,b){this.name=a;this.pass=c;this.remember=b?1:0}});var ExerciseVO=Cairngorm.VO.extend({init:function(a,c,b){this.id=a;this.name=c;this.title=b}});var NewUserVO=Cairngorm.VO.extend({init:function(a,c,b,d,k,j,l){this.name=a;this.pass=c;this.realName=b;this.realSurname=d;this.email=k;this.activationHash=j;this.languages=l}});BP.control=new Controller;BP.Services=new ApiGateway;BP.Services.getCommunicationToken();BP.onCommunicationReady=function(){BP.EM=new ExerciseManager;BP.CM=new ConfigurationManager};
$.get("themes/babelium/js/services.xml",null,function(a){var c={};$(a).find("gateway").each(function(){var a=$(this);a.attr("type")=="http"&&(c[a.attr("id")]={target:a.attr("target"),method:a.attr("method")})});$(a).find("service").each(function(){var a=$(this),d=c[a.attr("destination")];d!=null&&(d=new Cairngorm.HTTPService(d,a.attr("class")),Cairngorm.ServiceLocator.registerHttpService(a.attr("id"),d))})});$(document).ready(function(){BP.SM.init();BP.CMS.init();window.onpopstate=BP.SM.onPopState});
function onConnectionReady(a){var c=null;(c=navigator.appName.indexOf("Microsoft")!=-1?window[a]:document[a])?a=="babeliumPlayer"?BP.SM.at("practice")?BP.EM.selectedExercise?BP.EM.loadSelectedExercise(c):BP.EM.loadExerciseFromContent(c):BP.SM.at("evaluate")&&BP.EM.loadResponseFromContent(c):a=="babeliumMicTester"?BP.CM.setupComponent(c,"mic"):a=="babeliumWebcamTester"&&BP.CM.setupComponent(c,"webcam"):alert("There was a problem while loading the SWF component.")};
